package com.csu.csumall.VO;

import com.csu.csumall.entity.Order;
import com.csu.csumall.entity.OrderItem;
import com.csu.csumall.entity.PayInfo;
import com.csu.csumall.entity.Shipping;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 订单详情页
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDetailVO {

    private Integer orderId;
    private Integer orderStatus;

    private String addressName;
    private String addressMobile;
    private String address;

    private List<OrderProductVO> OrderProductVOList = new ArrayList<>();

    private Integer payPlatform;
    private BigInteger orderNo;
    private String platformNumber;

    private LocalDateTime createTime;
    private LocalDateTime paymentTime;
    private LocalDateTime sendTime;
    private LocalDateTime closeTime;
    private LocalDateTime endTime;

    @JsonIgnore
    public OrderDetailVO(Order order, Shipping shipping, List<OrderItem> orderItemList, PayInfo payInfo) {

        orderId = order.getId();
        orderStatus = order.getStatus();

        addressName = shipping.getAddressName();
        addressMobile = shipping.getAddressMobile();
        address = shipping.getAddressProvince() + " " + shipping.getAddressCity() + " " + shipping.getAddressDistrict()
                + shipping.getAddressDistrict() + " " + shipping.getAddressDetail();

        orderItemList.forEach(orderItem -> {
            OrderProductVOList.add(new OrderProductVO(orderItem));
        });

        payPlatform = payInfo.getPayPlatform();
        orderNo = order.getOrderNo();
        platformNumber = payInfo.getPlatformNum();

        createTime = order.getCreateTime();
        paymentTime = order.getPaymentTime();
        sendTime = order.getSendTime();
        closeTime = order.getCloseTime();
        endTime = order.getEndTime();
    }

}


